<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('商品列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label style="width: 80px;">产品编号：</label>
                                <input type="text" name="gdNumber"/>
                            </li>
                            <li>
                                <label style="width: 80px;">状态：</label>
                                <select name="state">
                                    <option value="">所有</option>
                                    <option value="1">上架</option>
                                    <option value="2">下架</option>
                                </select>
                            </li>
                            <li>
                                <label style="width: 80px;">终端类型：</label>
                                <select name="posType">
                                    <option value="">所有</option>
                                    <option value="4">电签</option>
                                    <option value="0">传统</option>
                                    <option value="5">GB传统</option>
                                    <option value="6">GB电签</option>
                                    <option value="7">GB电签二</option>

                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="GoodsInfo:GoodsInfo:add">
                    <i class="fa fa-plus"></i> 添加商品
                </a>
              <!--  <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="GoodsInfo:GoodsInfo:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="GoodsInfo:GoodsInfo:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="GoodsInfo:GoodsInfo:export">
                    <i class="fa fa-download"></i> 导出
                </a>-->
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('GoodsInfo:GoodsInfo:edit')}]];
        var removeFlag = [[${@permission.hasPermi('GoodsInfo:GoodsInfo:remove')}]];
        var prefix = ctx + "GoodsInfo/GoodsInfo";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "商品",
                columns: [
                    {
                        field: 'id',
                        title: 'id',
                        visible: false
                    },
                {
                    field: 'gdNumber',
                    title: '产品编号'
                },
                {
                    field: 'posType',
                    title: '终端类型',
                    formatter:function(value,row,index){
                        if (value == '0'){
                            return "<span style='color: blue'>传统</span>";
                        } else if (value == '4'){
                            return "<span style='color: green'>电签</span>";
                        } else if (value == '5'){
                            return "GB传统";
                        } else if (value == '6'){
                            return "GB电签";
                        }else if (value == '7'){
                            return "GB电签二";
                        } else {
                            return "";
                        }
                    }
                },
                {
                    field: 'mianTitle',
                    title: '主标题'
                },
                {
                    field: 'subTitle',
                    title: '副标题'
                },
                {
                    field: 'price',
                    title: '售价'
                },
                {
                    field: 'details',
                    title: '介绍详情'
                },
                {
                    field: 'remarks',
                    title: '备注'
                },
                {
                    field: 'state',
                    title: '状态',
                    formatter:function(value,row,index){
                        return statusTools(row);
                    }
                },
                {
                    field: 'soldNum',
                    title: '已售总数量'
                },
                {
                    field: 'nums',
                    title: '起购台数'
                },
                {
                    field: 'oldPrice',
                    title: '划线价'
                },
                {
                    field: 'costPrice',
                    title: '成本价格'
                },
                {
                    field: 'fictitiousStock',
                    title: '虚拟库存'
                },
                {
                    field: 'freightMoney',
                    title: '运费'
                },
                {
                    field: 'stock',
                    title: '真实库存'
                },
                {
                    field: 'sorts',
                    title: '排序'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });


        /* 商品状态 */
        function statusTools(row) {
            if (row.state == 1) {
                return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
            } else {
                return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
            }
        }

        /* 商品状态-停用 */
        function disable(id) {
            $.modal.confirm("确认要下架当前商品吗？", function() {
                $.operate.post(prefix + "/edit", { "id": id, "state": 2});
            })
        }

        /* 商品状态-启用 */
        function enable(id) {
            $.modal.confirm("确认要上架当前商品吗？", function() {
                $.operate.post(prefix + "/edit", { "id": id, "state": 1});
            })
        }

        /* 前往编辑商品页面 */
        function edit(id) {
            $.modal.open("新增商品",prefix + "/edit?id=" + id,"800","750");
        }

    </script>
</body>
</html>
